package com.amigo.online.provider.common.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.common.base.exception.IllegalParameterException;
import com.amigo.online.common.base.service.BaseService;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.param.dto.video.AreaDto;
import com.amigo.online.common.param.result.AreaInfo;
import com.amigo.online.provider.common.mapper.BusiAreaMapper;
import com.amigo.online.provider.common.model.entity.BusiArea;
import com.amigo.online.provider.common.service.BusiAreaService;
import com.amigo.online.provider.common.util.ConvertUtil;

@Service
@Transactional(rollbackFor = Exception.class)
public class BusiAreaServiceImpl extends BaseService<BusiArea> implements BusiAreaService {

    @Resource
    BusiAreaMapper busiAreaMapper;

    @Override
    public List<AreaInfo> linkageQuery(AreaDto dto) {
        if (dto.getPid() == null || dto.getLevel() == null) {
            throw new IllegalParameterException(StatusCode.BAD_REQUEST);
        }
        List<BusiArea> areaList = busiAreaMapper.linkageQuery(dto);
        List<AreaInfo> areaInfoList = new ArrayList<AreaInfo>();
        for (BusiArea busiArea : areaList) {
            AreaInfo areaInfo = ConvertUtil.BusiAreaToAreaInfo(busiArea, dto);
            areaInfoList.add(areaInfo);
        }
        return areaInfoList;
    }
}
